//本地stream
var localStream:any = null;
//启动摄像头
function startCamera(video_id:string) {
    //启动摄像头
    if (localStream == null) {
        navigator.mediaDevices
            .getUserMedia({
                audio: true,
                video: true
            })
            .then(stream => {
                localStream = stream
                bindStream(video_id)
            })
            .catch(e => alert('getUserMedia() error: ${e.name}'));
    }
    bindStream(video_id)
}

//绑定本地摄像头流至video展示
function bindStream(id:string) {
    console.log('Received local stream');
    $(id).srcObject = localStream;
}

function $(id:string) {
    return document.getElementById(id);
}

export {startCamera};